#include "sTRStretch.h"


namespace sgui
{
namespace res
{ 

void sTextureResourceStretch::save(db::Record& file) const
{
	db::Record &horDividers = file[L"hd"];
	db::Record &vertDividers = file[L"vd"];
	horDividers.setSize(ESD_COUNT);
	vertDividers.setSize(ESD_COUNT);
	for (u32 i = 0; i < ESD_COUNT; ++i)
	{
		horDividers[i].Set(m_horisontalDividers[i]);
		vertDividers[i].Set(m_verticalDividers[i]);
	}

	file[L"ch"].Set((u32)m_center.horisontal);
	file[L"cv"].Set((u32)m_center.vertical);

	file[L"_t"].Set((u32)m_top);
	file[L"_b"].Set((u32)m_bottom);
	file[L"_l"].Set((u32)m_left);
	file[L"_r"].Set((u32)m_right);
}

void sTextureResourceStretch::load(const db::Record& file)
{
	const db::Record &horDividers = file[L"hd"];
	const db::Record &vertDividers = file[L"vd"];

	for (u32 i = 0; i < ESD_COUNT; ++i)
	{
		m_horisontalDividers[i] = horDividers[i].GetAsFloat();
		m_verticalDividers[i] = vertDividers[i].GetAsFloat();
	}
	
	m_center.horisontal = (EStretchMode)file[L"ch"].GetAsInt();
	m_center.vertical = (EStretchMode)file[L"cv"].GetAsInt();

	m_top = (EStretchMode)file[L"_t"].GetAsInt();
	m_bottom = (EStretchMode)file[L"_b"].GetAsInt();
	m_left = (EStretchMode)file[L"_l"].GetAsInt();
	m_right = (EStretchMode)file[L"_r"].GetAsInt();
}

void sTextureResourceStretch::clear()
{
	for (u32 i = 0; i < ESD_COUNT; ++i)
	{
		m_horisontalDividers[i] = 0;
		m_verticalDividers[i] = 0;
	}
	
	m_center.horisontal = ESM_STRETCH;
	m_center.vertical = ESM_STRETCH;

	m_top = ESM_STRETCH;
	m_bottom = ESM_STRETCH;
	m_left = ESM_STRETCH;
	m_right = ESM_STRETCH;
}

#ifdef _EDITOR
void sTextureResourceStretch::exportRTTI(rtti::sInfoList& list)
{

}
#endif

sTextureResourceStretch::sTextureResourceStretch() :
	m_top(ESM_STRETCH),
	m_bottom(ESM_STRETCH),
	m_left(ESM_STRETCH),
	m_right(ESM_STRETCH)
{

}

};
};